$(
  (function (win) {
    win.videoInit = ({ videoId, buttonId }) => {
      const video = $(`#${videoId}`)[0];
      const videoButton = $(`#${buttonId}`);
      if (video) {
        $(video).removeAttr('controls')
        // 监听开始
        $(`#${videoId}`).on('play', () => {
          videoButton.fadeOut(500);
        });
        // 监听暂停
        $(`#${videoId}`).on('pause', () => {
          videoButton.fadeIn(500);
          // $(video).removeAttr('controls')
        });
        // 点击播放
        videoButton.click(() => {
          // if(video.isplay){
          //   return
          // }
          video.play();
          $(video).attr('controls','controls')
          video.isplay=true
        });
      }
    };
    win.getUrlData = (name) => {
      var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
      var r = decodeURIComponent(window.location.search).substr(1).match(reg);
      if (r != null) {
        return unescape(r[2]);
      }
      return null;
    };

    setTimeout(() => {
      // console.log($('#returnBack'), $('#toSearch'));
      // 点击搜索 -> 顶部 -> 打开
      $('#searchOpen').click(() => {
        $('#header').removeClass('showSearch');
        $('.h-box').addClass('active');
      });
      // 点击搜索 -> 顶部 -> 关闭
      $('#searchClose').click(() => {
        $('#header').addClass('showSearch');
        $('.h-box').removeClass('active');
      });
      // 返回上一页
      $('#returnBack').click(() => {
        console.log('返回上一页');
        win.history.back();
      });
      // 跳转搜索页
      $('.toLink').click(searchFun);
      function searchFun() {
        const searchUrl = $(this).parent().attr('searchUrl');
        win.location.href =
          searchUrl + encodeURIComponent($('#searchInput').val());
      }
      $('#searchInput').keydown(function (e) {
        if (e.which == 13) {
          searchFun.call(this);
        }
      });
      // 从URL上读取搜索值
      if (win.getUrlData('keywords')) {
        const key = win.getUrlData('keywords');
        $('#searchInput').val(key);
        console.log(
          '已从URL上获取搜索关键词【' + key + '】，可以开始搜索了...'
        );
      }
      // 搜索查询数据
      $('.searchButton').click(() => {
        alert('查询数据');
      });
    }, 1500);
  })(window)
);
